#include<iostream>
using namespace std;
const int N = 210;
int dis[N][N];
int INF = 1e9;
int n, m, k;
void Floyd()
{
	for (int k = 1; k <= n; k++) {
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
			}
		}
	}
}
int main()
{
	cin >> n >> m >> k;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (i == j)dis[i][j] = 0;
			else {
				dis[i][j] = INF;
			}
		}
	}
	while (m--) {
		int a, b, w;
		cin >> a >> b >> w;
		dis[a][b] = min(dis[a][b], w);
	}
	Floyd();
	while (k--) {
		int a, b;
		cin >> a >> b;
		if (dis[a][b] > INF / 2) {
			cout << "impossible" << endl;
		}
		else {
			cout << dis[a][b] << endl;
		}
	}
	return 0;
}